package com.learn.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * 从 Spring Framwork 中获取对象
 */
public class SpringBeans implements BeanFactoryAware {

    private static BeanFactory beanFactory = null;

    public void setBeanFactory(BeanFactory bf) throws BeansException {
        SpringBeans.beanFactory = bf;
    }

    public static Object getBean(String beanName) {
        return beanFactory.getBean(beanName);
    }

    public static Object getBean(Class<?> type) {
        return beanFactory.getBean(type);
    }
}
